package Demo;

public class Main {
    public static void main(String[] args) {
//        int[] array = {123,54,65,8,456,1234,69,4,65,12,213,156,999};
//        int min = find(array, new Find() {
//            @Override
//            public boolean show() {
//                return false;
//            }
//        });
//        int max = find(array, new Find() {
//            @Override
//            public boolean show() {
//                return true;
//            }
//        });
        int[] array = {123,54,65,8,456,1234,69,4,65,12,213,156,999};
        int min = find(array, () -> false);
        int max = find(array, () ->  true);
        System.out.println("min = " + min + " max = " + max);
    }

    public static int find(int[] array, Find f) {
        int ret = array[0];
        for(int i = 1;i < array.length;i++) {
            if(f.show()) {
                // 最大
                if(ret < array[i]) {
                    ret = array[i];
                }
            }else {
                // 最小
                if(ret > array[i]) {
                    ret = array[i];
                }
            }
        }
        return ret;
    }
}